<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>计算属性的基本使用</title>
</head>
<body>
    <div id="app">
        <h2>总价格：{{totalPrice}}</h2>
    </div>
</body>
    <script src="../js/vue.js"></script>
    <script>
        var app = new Vue({
            el: '#app',
            data: {
                books: [
                    {id: 1101, name: 'SpringBoot入门', price: 50},
                    {id: 1102, name: '计算机原理', price: 60},
                    {id: 1103, name: 'JavaWeb基础', price: 49},
                ],
            },
            computed: {
                totalPrice: function () {
                    //return this.books.reduce();
                    let result = 0;
                    for(let i=0; i<this.books.length; i++){
                        result += this.books[i].price
                    }
                    return result
                }
            }
        })
    </script>
</html>